<?php
/**
 * Created by PhpStorm.
 * User: HBB-ice
 * Date: 2015/7/30
 * Time: 11:58
 */

namespace Apps\Common\Libs;


use PhalconPlus\Common\Component;

class UserCommon extends Component
{
    /**
     * 密码加密
     * @param $pwd
     * @param \Phalcon\DiInterface|null $di
     * @return string
     */
    public static function hashPassword($pwd, $di=null)
    {
        $di = !!$di ? $di : self::getDI();
        $config = $di->get('appConfig');
        $signKey = 'phalcon.ice.deng';
        if($config->offsetExists('application') && $config->application->offsetExists('cryptKey')) {
            $signKey = $config->application->cryptKey;
        }
        $str = is_string($pwd) ? $pwd : json_encode($pwd);
        return strtolower(md5($str . $signKey));
    }
}